package sample.dubbo.async;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.remoting.exchange.ResponseCallback;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter;

/**
 * @date 2020/8/26
 */
public class ConsumerSample {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		ApplicationConfig appConfig = new ApplicationConfig();
		appConfig.setName("async-consumer-sample");
		RegistryConfig registryConfig = new RegistryConfig();
		registryConfig.setAddress("multicast://224.5.6.7:1234");
		ReferenceConfig referenceConfig = new ReferenceConfig();
		referenceConfig.setInterface(ProviderSample.FooService.class);
		//referenceConfig.setAsync(true);
		referenceConfig.setTimeout(6000);
		referenceConfig.setRegistry(registryConfig);
		referenceConfig.setApplication(appConfig);
		ProviderSample.FooService fooService = (ProviderSample.FooService) referenceConfig.get();

		RpcContext context = RpcContext.getContext();
		context.getAttachments().put("A", "A");
		fooService.doFoo();

		context = RpcContext.getContext();
		System.out.println("A->" + context.getAttachment("A"));
		fooService.doFoo();

		context = RpcContext.getContext();
		System.out.println("A->" + context.getAttachment("A"));
		fooService.doFoo();
		new CountDownLatch(1).await();
	}

}
